/**
 * @Description:
 * @Author 卞鹏飞 <228443632@qq.com>
 * @create 14/08/24 5:10 PM
 */
// types
import type { RouteLocationNormalized } from 'vue-router'
import type { TRouter } from '@root/types/router.ts'
import type { IAppStateTabItem } from '@root/types/app-store.ts'

/**
 * 执行函数关闭之前路由 参数 选项类型
 */
export type TBeforeCloseRouteValueOptions = {
  to?: RouteLocationNormalized
  from?: RouteLocationNormalized
  done?: Function
  router?: TRouter
}

/**
 * 执行函数关闭之前路由 返回值类型
 */
export type TBeforeCloseRouteValue = ((options: TBeforeCloseRouteValueOptions) => boolean | Promise<boolean>) & {
  key?: string
}

export type TDone = (doneOptions?: { autoJump?: boolean }) => void

/**
 * layout-store state参数类型
 */
export type TLayoutState = {
  /**
   * 接口请求loading
   */
  xhrLoading: boolean
  /**
   * 应用loading
   */
  loading: boolean
  /**
   * 页面 路由是否缓存
   */
  pageCache: boolean
  /**
   * 是否展示header头部
   */
  isHeaderShow: boolean
  /**
   * 是否展示tab
   */
  isTabShow: boolean
  /**
   * 是否展示菜单
   */
  isMenuShow: boolean
  /**
   * 是否折叠
   */
  collapse: boolean
  /**
   * tab 每一项对象
   */
  tabs: IAppStateTabItem[]
  beforeCloseRoute: {
    [K in string]: TBeforeCloseRouteValue[] & { status?: 'pending' | 'resolve' | '' }
  }

  beforeCloseRouteV2: {
    [K in string]: (options: { done?: TDone }) => Promise<boolean>
  }

  /**
   * 移除iframe缓存，一般开发人员用不到
   */
  removeIframeRoute: Function
  /**
   * 重新刷新路由
   * @param {{key: string} | string} tab tab唯一标识
   */
  reloadRoute: (tab: { key: string } | string, options?: Record<string, any>) => void
  /**
   * 当前选中的tab
   */
  tabsActive: string
  /**
   * 当前菜单激活的
   */
  menuActive: string
}

/**
 * tab类型
 */
export type TabItemUnion = IAppStateTabItem | string
